package cn.wizzer.app.cms.modules.services.impl;

import cn.wizzer.app.cms.modules.models.CmsArticle;
import cn.wizzer.app.cms.modules.services.CmsArticleService;
import cn.wizzer.framework.base.service.BaseServiceImpl;
import cn.wizzer.framework.base.service.CommonDBService;
import cn.wizzer.framework.page.Pagination;
import com.alibaba.dubbo.config.annotation.Service;
import org.nutz.dao.Condition;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
import org.nutz.plugins.wkcache.annotation.CacheResult;

@IocBean(args = {"refer:dao"})
@Service(interfaceClass = CmsArticleService.class)
@CacheDefaults(cacheName = "cms_article")
public class CmsArticleServiceImpl extends BaseServiceImpl<CmsArticle> implements CmsArticleService {
    public CmsArticleServiceImpl(Dao dao) {
        super(dao);
    }

    @Inject
    private CommonDBService dbService;

    @CacheResult
    public Pagination getListPage(int pageNumber, int pageSize, Condition cnd) {
        Sql sql = Sqls.create("select id,channelId,title,picurl,author from cms_article $condition ");
        sql.setCondition(cnd);
        Sql countSql = Sqls.create("select count(1) count from cms_article $condition ");
        countSql.setCondition(cnd);
        return dbService.listPage(CmsArticle.class, pageNumber, pageSize, sql.toString(), countSql.toString());
    }

    @CacheResult
    public CmsArticle getArticle(Condition cnd) {
        return this.fetch(cnd);
    }

    @CacheRemoveAll
    public void clearCache() {

    }
}
